package sibu.cn.mydemo;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * Created by 刘红亮 on 15-11-6 下午5:22.
 */
public class ListViewAdapter extends BaseAdapter {

    Context context;
    String arr[];

    public ListViewAdapter(Context context,String[] arr){
        this.context = context;
        this.arr = arr;
    }

    @Override
    public int getCount() {

        return arr.length;
    }

    @Override
    public Object getItem(int position) {
        if(arr.length!=0){
           return arr[position];
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView==null){
            convertView = LayoutInflater.from(context).inflate(R.layout.detail_item_layout,parent,false);
            viewHolder = new ViewHolder();
            viewHolder.textView = (TextView) convertView.findViewById(R.id.txt_content);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.textView.setText(arr[position]);

        return convertView;
    }

    public void setArr(String[] arr) {
        this.arr = arr;
        notifyDataSetChanged();
    }

    class  ViewHolder{
     public  TextView textView;

    }
}
